// 引入 request 方法，假设 request 方法已经定义在某个工具文件中
import request from '/@/utils/request';
import {
    AddSubscribeMessageTemplateInput,
    GenerateQRImageInput, 
    SendSubscribeMessageInput,
    WxOpenIdLoginInput,
    SetNickNameInput,
} from '../models';
// 定义 API 路径枚举
enum Api {
    AddSubscribeMessageTemplate = '/sysWxOpen/addSubscribeMessageTemplate',
    GenerateQRImage = '/sysWxOpen/generateQRImage',
    MessageTemplateList = '/sysWxOpen/messageTemplateList',
    SendSubscribeMessage = '/sysWxOpen/sendSubscribeMessage',
    SetNickName = '/sysWxOpen/setNickName',
    UploadAvatar = '/sysWxOpen/uploadAvatar',
    UserInfo = '/sysWxOpen/userInfo/',
    WxOpenId = '/sysWxOpen/wxOpenId',
    WxOpenIdLogin = '/sysWxOpen/wxOpenIdLogin',
    WxPhone = '/sysWxOpen/wxPhone',
}

// 定义 API 方法
export const apiSysWxOpenAddSubscribeMessageTemplatePost = (body: AddSubscribeMessageTemplateInput) =>
    request({
        url: Api.AddSubscribeMessageTemplate,
        method: 'post',
        data: body,
    });

export const apiSysWxOpenGenerateQRImagePost = (body: GenerateQRImageInput) =>
    request({
        url: Api.GenerateQRImage,
        method: 'post',
        data: body,
    });

export const apiSysWxOpenMessageTemplateListGet = () =>
    request({
        url: Api.MessageTemplateList,
        method: 'get',
    });

export const apiSysWxOpenSendSubscribeMessagePost = (body: SendSubscribeMessageInput) =>
    request({
        url: Api.SendSubscribeMessage,
        method: 'post',
        data: body,
    });

export const apiSysWxOpenSetNickNamePost = (body: SetNickNameInput) =>
    request({
        url: Api.SetNickName,
        method: 'post',
        data: body,
    });

export const apiSysWxOpenUploadAvatarPostForm = (openId?: string, file?: Blob, fileType?: string, path?: string) => {
    const formData = new FormData();
    if (openId) formData.append('OpenId', openId);
    if (file) formData.append('File', file);
    if (fileType) formData.append('FileType', fileType);
    if (path) formData.append('Path', path);
    return request({
        url: Api.UploadAvatar,
        method: 'post',
        data: formData,
    });
};

export const apiSysWxOpenUserInfoOpenidGet = (openid: string) =>
    request({
        url: `${Api.UserInfo}${openid}`,
        method: 'get',
    });

export const apiSysWxOpenWxOpenIdGet = (jsCode: string) =>
    request({
        url: `${Api.WxOpenId}?JsCode=${jsCode}`,
        method: 'get',
    });

export const apiSysWxOpenWxOpenIdLoginPost = (body: WxOpenIdLoginInput) =>
    request({
        url: Api.WxOpenIdLogin,
        method: 'post',
        data: body,
    });

export const apiSysWxOpenWxPhoneGet = (code: string, openId: string) =>
    request({
        url: `${Api.WxPhone}?Code=${code}&OpenId=${openId}`,
        method: 'get',
    });